Can't see the error

Hello, and sorry again...I don't like to keep asking help, but I'm not seeing what is wrong.
I open some modules in exclusive edit and run the dxl, that should fill this modules, but when I run the follow script I receive this message:
-R-E- DXL: <Line:219> unassigned variable (m)
Backtrace:

  • <Line:219>*

-I- DXL: execution halted

 

/*===========================================================================================
 Date: ??/08/2011
 Bruna Aquino
==========================================================================================*/
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                        //////////////  Variables //////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
Project pSys = project "/EMB550_04_Systems"
Object obj = current
Module m
int iQC1, iQC2
string currentQC1, currentQC2
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                                  /////////////// Interface Items ////////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
DB verEvidenceBox = create("Synoptics Completeness Validation Checklist - Rev (-)")
 
DBE tagField, statusField, authorField
DBE selectChoiceQC1, selectChoiceQC2
DBE richTextReq, richTextApp, textMultiLine, selectHelp
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                             ///////////////    Answer Types ////////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
string options[] = {"YES", "NO", "Not Evaluated"}
string errMess = "Error creating type."
 
AttrType answerType = find(current Module, "Answer")
 
if (null answerType) answerType = create ("Answer", options, errMess)
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                                        ///////////////  Functions  //////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
void deleteAttrDef(string s){ 
  AttrDef ad = find(current Module, s) 
  if (null ad) // print "Attr Def  '" s "' does not exist.\n"
  else delete(ad) 
} 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
 
void deleteAttrType(string s){
  string err = "" 
  AttrType at = find(current Module, s)   
  if (null at) // print "Attr Type  '" s "' does not exist.\n"
  else delete(at, err)  
} 
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
// Status field will always reflect the actual answers for all questions
void setStatus(Module m){     
    Project pSys = project "/EMB550_04_Systems"
        bool ValInd, NotEvalInd, NotValInd
        ValInd = false
        NotEvalInd = false
        NotValInd = false
        
        for m in pSys do {
        if (isEdit(m)){
        if (m."Validation Q1CSYS" ""=="YES" && m."Validation Q2CSYS" ""=="YES") {
                          ValInd = true
                          }  
        else {       
        if (m."Validation Q1CSYS" ""=="Not Evaluated" && m."Validation Q2CSYS" ""=="Not Evaluated") {
                                          NotEvalInd = true
                                         }else NotValInd = true 
                                }
        
                if (NotValInd) {
                        m."Completeness Validation Status" = "Not Valid"
                        } else if (NotEvalInd){
                        m."Completeness Validation Status" =  "Not Validated"
                        } else m."Completeness Validation Status" = "Valid" ""
        }
   if (!isEdit(m)) then 
   infoBox "Open module as Shareable or Exclusive Edit."; continue
    }
}
 
  
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/          
// Return the last author of the current object
string lastObjectTextModifier(){
        History h 
        string lastAuthor = ""
    for h in current Object do {
            HistoryType ht = h.type 
                if (ht == modifyObject && h.attrName == "Object Text") lastAuthor = h.author 
        }
        return lastAuthor
}
 
void updateVariables(Module m) {
        for m in pSys do {
        string currentQC1 = m."Validation Q1CSYS" ""
        string currentQC2 = m."Validation Q2CSYS" ""
                        
        for iQC1 in 0:3 by 1 do {
                if (currentQC1 == answerType.strings[iQC1]) { break }
                iQC1++
        }
        for iQC2 in 0:3 by 1 do {
                if (currentQC2 == answerType.strings[iQC2]) { break }
                iQC2++
        }
                        
        set(selectChoiceQC1,iQC1)
        set(selectChoiceQC2,iQC2)
        set(textMultiLine, m."Completeness Validation Comments" "")
        setStatus(m)            
        refresh m
    }
}
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
bool notExistAttribute(string aName){        
        AttrDef ad = find(current Module, aName) 
        if (null ad) return true
        else return false
}
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
 
// Save all validation questions and Validation Comments
void saveObjects(Module m){
    User u = find() // returns current user login.
    string userLogin = u.name
        string aux = ""
        int i
        bool wasModified = false
                
        if (get(selectChoiceQC1) =="NO" || get(selectChoiceQC1)=="NO" ) {
                        if (get(textMultiLine) == "") {
                                warningBox("Add comments that describe why the requirement is not valid or the data entered will not be saved.\nThis will help author to correct the requirement.")
                                return
                        }
                }
        
           if(canModify(m)){
                    
                        aux = get(selectChoiceQC1)
                        if(m."Validation Q1CSYS" "" != aux) {
                                m."Validation Q1CSYS" = aux
                                wasModified = true
                                }
                        aux = get(selectChoiceQC2)
                        if(m."Validation Q2CSYS" "" != aux) {
                                m."Validation Q2CSYS" = aux
                                wasModified = true
                                }            
                                
                    aux = get(textMultiLine)
                        if(m."Completeness Validation Comments" "" != aux) {
                                m."Completeness Validation Comments" = get(textMultiLine)
                                wasModified = true
                        }
                                                // Save checker
                        if(wasModified){     // Saves Checker just if something has changed.
                                User u = find() // returns current user login.          
                                string uName    = u.name
                                obj."Completeness Checker" = uName// just save if is requirement.
                        }
                        
        }                    
                
        else infoBox "Cannot modify current object."
}
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
void saveReport(DB calledFrom){              
        saveObjects(m) // Saves all validation questions and Validation Comments.       
        save(m)
        refresh (m)     
}
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
void closeBox(DB calledFrom){        
        if(unsaved(Module m)){                       
                string buttons[] = {"Yes", "No"} 
                int answer = messageBox("To save the validation, save current module. \nSave current module?", buttons, msgWarning) 
                if(buttons[answer] == "Yes") {
                        saveObjects(m) // Saves all validation questions and Validation Comments.       
                        save(m)
                        refresh (m)     
                }    
        }
        hide calledFrom
}
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
bool notExistAttribute(string attrName){
        AttrDef ad = find(current Module, attrName) 
        if (null ad) return true
        else {
 
                return false
        }
}
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                        //////////////////  Main Program  //////////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
 
// Start to buid GUI
    saveButton = apply(verEvidenceBox, "&Save Module", saveReport)
        close(verEvidenceBox, true, closeBox)
 
        // Questions 
        selectChoiceQC1 = choice(verEvidenceBox, "Q1: ?", options, 1, 13,false)
        
        selectChoiceQC2 = choice(verEvidenceBox, "Q2: ?", options, 1, 13,false)
                
        statusField = field(verEvidenceBox, "Completeness Validation Status", "", 13, true)
        
        textMultiLine = text(verEvidenceBox, "Completeness Validation Comments","", 30, 60, false )
        
        realize verEvidenceBox
        updateVariables(m)      
        show verEvidenceBox



Anyway...like always I will keep trying to find the answer myself, maybe a coffe or a walk may clear my mind and help me.
If I find the answer I post here...if anyone find it first, I thank you!



 


Bruwbruw - Fri Aug 10 09:02:00 EDT 2012

Re: Can't see the error
llandale - Fri Aug 10 10:50:52 EDT 2012

It would be easier if you tell us which is line 219, in this case 2nd from last line:
  • updateVariables(m)

I think if you remove "m" as a call parameter to updateVariables() it will work.
Function "updateVariables(Module m)" accepts "m", but immediately does this
  • for m in pSys do
that only makes sense if for some reason you want to return the LAST open module in the Project.

I see that...
  • "m" is a global variable
  • "m" is an input parameter to many functions.
  • No function that refers to "m" does not have it also as an input parameter. That is, no function access the global "m"
  • line 219 is the only line referencing global "m".

Thus, of course, it's not yet defined.

I used to make this mistake quite a lot so I adopted conventions that:
  • Globally defined variables start with "g_" or global constants "c_"
  • function parameters start with "in_", "&out_", or "&inout_".
  • function's local variables do neither of the above.
So I can look at a variable and know its exact declared context.

There are indeed some very sharp folks who can remember and handle sloppy names, but the rest of us need more discipline.
And the sharp folks need to accept that dull folks are going to read their code eventually.

-Louie

Your indentation bytes. Thank goodness your clean short well-defined functions mitigate that rather serious flaw.
Consider turning on "show tab characters" and "show matching braces" in your editor.

Re: Can't see the error
Bruwbruw - Wed Aug 15 08:26:32 EDT 2012

llandale - Fri Aug 10 10:50:52 EDT 2012
It would be easier if you tell us which is line 219, in this case 2nd from last line:

  • updateVariables(m)

I think if you remove "m" as a call parameter to updateVariables() it will work.
Function "updateVariables(Module m)" accepts "m", but immediately does this
  • for m in pSys do
that only makes sense if for some reason you want to return the LAST open module in the Project.

I see that...
  • "m" is a global variable
  • "m" is an input parameter to many functions.
  • No function that refers to "m" does not have it also as an input parameter. That is, no function access the global "m"
  • line 219 is the only line referencing global "m".

Thus, of course, it's not yet defined.

I used to make this mistake quite a lot so I adopted conventions that:
  • Globally defined variables start with "g_" or global constants "c_"
  • function parameters start with "in_", "&out_", or "&inout_".
  • function's local variables do neither of the above.
So I can look at a variable and know its exact declared context.

There are indeed some very sharp folks who can remember and handle sloppy names, but the rest of us need more discipline.
And the sharp folks need to accept that dull folks are going to read their code eventually.

-Louie

Your indentation bytes. Thank goodness your clean short well-defined functions mitigate that rather serious flaw.
Consider turning on "show tab characters" and "show matching braces" in your editor.

Hi, I have spend some days without work in my own code, plus my own doubt on how to proceed , take those two and its never a good combination...
Anyway, I have searched in the forums, and did some modification.
I got almost everything I want, but the GUI doenst work.
The question I have to do is:
"Does it make sense, or its possible, put inside a GUI dxl the loop to it fill the modules that are already open?"

/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                        //////////////  Variables //////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
Project pSys = project "/EMB550_04_Systems"
Object obj = current
Module m
Item itemRef
Skip modNameList = create
string parentPrj, parentFolder, moduleName, fullModName
int count = 0
int iQC1, iQC2
string currentQC1, currentQC2
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                                  /////////////// Interface Items ////////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
DB verEvidenceBox = create("Synoptics Completeness Validation Checklist - Rev (-)")
 
DBE tagField, statusField, authorField
DBE selectChoiceQC1, selectChoiceQC2
DBE richTextReq, richTextApp, textMultiLine, selectHelp
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                             ///////////////    Answer Types ////////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
string options[] = {"YES", "NO", "Not Evaluated"}
string errMess = "Error creating type."
AttrType answerType = find(current Module, "Answer")
if (null answerType) answerType = create ("Answer", options, errMess)
 
 // Projects that starts with '_' are not requirements.
bool matchPrj(string prjName){
        if(matches("(_)", prjName)) return false
        return true
}
 
// All formal modules inside SIR and SRS folders.
bool matchType(string modName){
        if ((matches("(SRS)", modName)) || (matches("(SIR)", modName))){ 
                return true
        }
        return false
} 
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                                        ///////////////  Functions  //////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
void deleteAttrDef(string s){ 
  AttrDef ad = find(current Module, s) 
  if (null ad) // print "Attr Def  '" s "' does not exist.\n"
  else delete(ad) 
} 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
 
void deleteAttrType(string s){
  string err = "" 
  AttrType at = find(current Module, s)   
  if (null at) // print "Attr Type  '" s "' does not exist.\n"
  else delete(at, err)  
} 
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
// Status field will always reflect the actual answers for all questions
void setStatus(Module &m){       
    string fullModName, str = ""
        bool ValInd, NotEvalInd, NotValInd
        ValInd = false
        NotEvalInd = false
        NotValInd = false
        fullModName = fullName(m)
 
        if (m."Validation Q1CSYS" ""=="YES" && m."Validation Q2CSYS" ""=="YES") {
                          ValInd = true
                          }  
        else {       
        if (m."Validation Q1CSYS" ""=="Not Evaluated" && m."Validation Q2CSYS" ""=="Not Evaluated") {
                                          NotEvalInd = true
                                         }else NotValInd = true 
                                }
        
                if (NotValInd) {
                        m."Completeness Validation Status" = "Not Valid"
                        } else if (NotEvalInd){
                        m."Completeness Validation Status" =  "Not Validated"
                        } 
                        else m."Completeness Validation Status" = "Valid" 
 }
 
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/          
void updateVariables(Module &m) {
string fullModName
fullModName = fullName(m)
        string currentQC1 = m."Validation Q1CSYS" ""
        string currentQC2 = m."Validation Q2CSYS" ""
                        
        for iQC1 in 0:3 by 1 do {
                if (currentQC1 == answerType.strings[iQC1]) { break }
                iQC1++
        }
        for iQC2 in 0:3 by 1 do {
                if (currentQC2 == answerType.strings[iQC2]) { break }
                iQC2++
        }
                        
        set(selectChoiceQC1,iQC1)
        set(selectChoiceQC2,iQC2)
        set(textMultiLine, m."Completeness Validation Comments" "")
        setStatus(m)            
        refresh (m)
 }
 
 
 /*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/ 
bool notExistAttribute(string aName){        
        AttrDef ad = find(current Module, aName) 
        if (null ad) return true
        else return false
}
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
 
// Save all validation questions and Validation Comments
void saveObjects(Module &m){
string fullModName
fullModName = fullName(m)
    User u = find() // returns current user login.
    string userLogin = u.name
        string aux = ""
        int i
        bool wasModified = false
        
    if (get(selectChoiceQC1) =="NO" || get(selectChoiceQC2)=="NO" ) {
        return
        }
            if(canModify(m)){
                    
                        aux = get(selectChoiceQC1)
                        if(m."Validation Q1CSYS" "" != aux) {
                                m."Validation Q1CSYS" = aux
                                wasModified = true
                                }
                        aux = get(selectChoiceQC2)
                        if(m."Validation Q2CSYS" "" != aux) {
                                m."Validation Q2CSYS" = aux
                                wasModified = true
                                }            
                                
                    aux = get(textMultiLine)
                        if(m."Completeness Validation Comments" "" != aux) {
                                m."Completeness Validation Comments" = get(textMultiLine)
                                wasModified = true
                        }
                                                // Save checker
                        if(wasModified){     // Saves Checker just if something has changed.
                                User u = find() // returns current user login.          
                                string uName    = u.name
                                obj."Completeness Checker" = uName// just save if is requirement.
                                }
                            }
 
        else infoBox "Cannot modify current object."
}
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
void saveReport(DB calledFrom){      
        saveObjects(m) // Saves all validation questions and Validation Comments.       
        save(m)
        refresh (m)     
 }
 
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
void closeBox(DB calledFrom){        
        if(unsaved(current Module)){                 
                string buttons[] = {"Yes", "No"} 
                int answer = messageBox("To save the validation, save current module. \nSave current module?", buttons, msgWarning) 
                if(buttons[answer] == "Yes") {
                        saveObjects(m) // Saves all validation questions and Validation Comments.       
                        save(m)
                        refresh (m)     
                }    
        }
        hide calledFrom
}
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
bool notExistAttribute(string attrName){
        AttrDef ad = find(current Module, attrName) 
        if (null ad) return true
        else {
 
                return false
        }
}

This part I'm doing the loop, the ideia is to get the answer I choose and loop throught the opened modules filling the attributes.

/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/     
for itemRef in pSys do{              
        if (type(itemRef) "" == "Formal"){ // Look up just formal modules.                               
                moduleName = name(itemRef)
                parentPrj = fullName(getParentProject(itemRef))
                if(matchPrj(parentPrj)){ // Just for some projects.
                        parentFolder = fullName(getParentFolder(itemRef))
                        if(matchType(parentFolder)){ // Just for some projects.
                                if(canModify(itemRef)){
                                        put(modNameList, name(itemRef), fullName(itemRef))                                                                                                              
                                        count++
                                }
                                else{
                                        print moduleName ": Cannot modify.\n"
                                }
                        }
                }
        }
}

This part is where the I'm having dificulties, I know how to open the modules, but I don't want to open it, I wanna to fill the ones already opened

for fullModName in modNameList do{
m = edit(fullModName, false)     
if(canModify(m)){
        setStatus(m)
                updateVariables(m)      
        save(m)
        close(m)
        }
}

Now the end of the dxl

/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                //////////////////  Main Program  //////////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
 
// Start to buid GUI
    saveButton = apply(verEvidenceBox, "&Save Module", saveReport)
        close(verEvidenceBox, true, closeBox)
 
        // Questions 
        selectChoiceQC1 = choice(verEvidenceBox, "Q1: ?", options, 1, 13,false)
        
        selectChoiceQC2 = choice(verEvidenceBox, "Q2: ?", options, 1, 13,false)
                
        statusField = field(verEvidenceBox, "Completeness Validation Status", "", 13, true)
        
        textMultiLine = text(verEvidenceBox, "Completeness Validation Comments","", 30, 60, false )
        
        realize verEvidenceBox
        updateVariables(m)      
        show verEvidenceBox

 

 

Re: Can't see the error
llandale - Wed Aug 15 10:42:35 EDT 2012

Bruwbruw - Wed Aug 15 08:26:32 EDT 2012

Hi, I have spend some days without work in my own code, plus my own doubt on how to proceed , take those two and its never a good combination...
Anyway, I have searched in the forums, and did some modification.
I got almost everything I want, but the GUI doenst work.
The question I have to do is:
"Does it make sense, or its possible, put inside a GUI dxl the loop to it fill the modules that are already open?"

/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                        //////////////  Variables //////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
Project pSys = project "/EMB550_04_Systems"
Object obj = current
Module m
Item itemRef
Skip modNameList = create
string parentPrj, parentFolder, moduleName, fullModName
int count = 0
int iQC1, iQC2
string currentQC1, currentQC2
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                                  /////////////// Interface Items ////////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
DB verEvidenceBox = create("Synoptics Completeness Validation Checklist - Rev (-)")
 
DBE tagField, statusField, authorField
DBE selectChoiceQC1, selectChoiceQC2
DBE richTextReq, richTextApp, textMultiLine, selectHelp
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                             ///////////////    Answer Types ////////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
string options[] = {"YES", "NO", "Not Evaluated"}
string errMess = "Error creating type."
AttrType answerType = find(current Module, "Answer")
if (null answerType) answerType = create ("Answer", options, errMess)
 
 // Projects that starts with '_' are not requirements.
bool matchPrj(string prjName){
        if(matches("(_)", prjName)) return false
        return true
}
 
// All formal modules inside SIR and SRS folders.
bool matchType(string modName){
        if ((matches("(SRS)", modName)) || (matches("(SIR)", modName))){ 
                return true
        }
        return false
} 
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                                        ///////////////  Functions  //////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
void deleteAttrDef(string s){ 
  AttrDef ad = find(current Module, s) 
  if (null ad) // print "Attr Def  '" s "' does not exist.\n"
  else delete(ad) 
} 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
 
void deleteAttrType(string s){
  string err = "" 
  AttrType at = find(current Module, s)   
  if (null at) // print "Attr Type  '" s "' does not exist.\n"
  else delete(at, err)  
} 
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
// Status field will always reflect the actual answers for all questions
void setStatus(Module &m){       
    string fullModName, str = ""
        bool ValInd, NotEvalInd, NotValInd
        ValInd = false
        NotEvalInd = false
        NotValInd = false
        fullModName = fullName(m)
 
        if (m."Validation Q1CSYS" ""=="YES" && m."Validation Q2CSYS" ""=="YES") {
                          ValInd = true
                          }  
        else {       
        if (m."Validation Q1CSYS" ""=="Not Evaluated" && m."Validation Q2CSYS" ""=="Not Evaluated") {
                                          NotEvalInd = true
                                         }else NotValInd = true 
                                }
        
                if (NotValInd) {
                        m."Completeness Validation Status" = "Not Valid"
                        } else if (NotEvalInd){
                        m."Completeness Validation Status" =  "Not Validated"
                        } 
                        else m."Completeness Validation Status" = "Valid" 
 }
 
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/          
void updateVariables(Module &m) {
string fullModName
fullModName = fullName(m)
        string currentQC1 = m."Validation Q1CSYS" ""
        string currentQC2 = m."Validation Q2CSYS" ""
                        
        for iQC1 in 0:3 by 1 do {
                if (currentQC1 == answerType.strings[iQC1]) { break }
                iQC1++
        }
        for iQC2 in 0:3 by 1 do {
                if (currentQC2 == answerType.strings[iQC2]) { break }
                iQC2++
        }
                        
        set(selectChoiceQC1,iQC1)
        set(selectChoiceQC2,iQC2)
        set(textMultiLine, m."Completeness Validation Comments" "")
        setStatus(m)            
        refresh (m)
 }
 
 
 /*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/ 
bool notExistAttribute(string aName){        
        AttrDef ad = find(current Module, aName) 
        if (null ad) return true
        else return false
}
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
 
// Save all validation questions and Validation Comments
void saveObjects(Module &m){
string fullModName
fullModName = fullName(m)
    User u = find() // returns current user login.
    string userLogin = u.name
        string aux = ""
        int i
        bool wasModified = false
        
    if (get(selectChoiceQC1) =="NO" || get(selectChoiceQC2)=="NO" ) {
        return
        }
            if(canModify(m)){
                    
                        aux = get(selectChoiceQC1)
                        if(m."Validation Q1CSYS" "" != aux) {
                                m."Validation Q1CSYS" = aux
                                wasModified = true
                                }
                        aux = get(selectChoiceQC2)
                        if(m."Validation Q2CSYS" "" != aux) {
                                m."Validation Q2CSYS" = aux
                                wasModified = true
                                }            
                                
                    aux = get(textMultiLine)
                        if(m."Completeness Validation Comments" "" != aux) {
                                m."Completeness Validation Comments" = get(textMultiLine)
                                wasModified = true
                        }
                                                // Save checker
                        if(wasModified){     // Saves Checker just if something has changed.
                                User u = find() // returns current user login.          
                                string uName    = u.name
                                obj."Completeness Checker" = uName// just save if is requirement.
                                }
                            }
 
        else infoBox "Cannot modify current object."
}
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
void saveReport(DB calledFrom){      
        saveObjects(m) // Saves all validation questions and Validation Comments.       
        save(m)
        refresh (m)     
 }
 
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
void closeBox(DB calledFrom){        
        if(unsaved(current Module)){                 
                string buttons[] = {"Yes", "No"} 
                int answer = messageBox("To save the validation, save current module. \nSave current module?", buttons, msgWarning) 
                if(buttons[answer] == "Yes") {
                        saveObjects(m) // Saves all validation questions and Validation Comments.       
                        save(m)
                        refresh (m)     
                }    
        }
        hide calledFrom
}
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/  
bool notExistAttribute(string attrName){
        AttrDef ad = find(current Module, attrName) 
        if (null ad) return true
        else {
 
                return false
        }
}

This part I'm doing the loop, the ideia is to get the answer I choose and loop throught the opened modules filling the attributes.

/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*====*/     
for itemRef in pSys do{              
        if (type(itemRef) "" == "Formal"){ // Look up just formal modules.                               
                moduleName = name(itemRef)
                parentPrj = fullName(getParentProject(itemRef))
                if(matchPrj(parentPrj)){ // Just for some projects.
                        parentFolder = fullName(getParentFolder(itemRef))
                        if(matchType(parentFolder)){ // Just for some projects.
                                if(canModify(itemRef)){
                                        put(modNameList, name(itemRef), fullName(itemRef))                                                                                                              
                                        count++
                                }
                                else{
                                        print moduleName ": Cannot modify.\n"
                                }
                        }
                }
        }
}

This part is where the I'm having dificulties, I know how to open the modules, but I don't want to open it, I wanna to fill the ones already opened

for fullModName in modNameList do{
m = edit(fullModName, false)     
if(canModify(m)){
        setStatus(m)
                updateVariables(m)      
        save(m)
        close(m)
        }
}

Now the end of the dxl

/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                //////////////////  Main Program  //////////////////
*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
 
// Start to buid GUI
    saveButton = apply(verEvidenceBox, "&Save Module", saveReport)
        close(verEvidenceBox, true, closeBox)
 
        // Questions 
        selectChoiceQC1 = choice(verEvidenceBox, "Q1: ?", options, 1, 13,false)
        
        selectChoiceQC2 = choice(verEvidenceBox, "Q2: ?", options, 1, 13,false)
                
        statusField = field(verEvidenceBox, "Completeness Validation Status", "", 13, true)
        
        textMultiLine = text(verEvidenceBox, "Completeness Validation Comments","", 30, 60, false )
        
        realize verEvidenceBox
        updateVariables(m)      
        show verEvidenceBox

 

 

This is impossible to follow, you need to post the entire code in one block.
What does "doesn't work" mean exactly?

I notice that Skip modNameList ..
  • has the base name as the "key"; which will fail if you have two modules with the same name open. Change the put() to one of these:
    • put(modNameList, fullName(itemRef), fullName(itemRef))
    • put(modNameList, itemRef, fullName(itemRef))
    • put(modNameList, count, fullName(itemRef))
  • has a 'string' key; so you MUST use "createString()" instead of just "create". (Unless you use "itemRef" or "count" as the key)

I think you want to use "for m in project do" to find Modules open in the Project. Looping for all items and using "canModify" doesn't feel right.
  • If so, this is an option:
    • put(modNameList, mod, fullName(itemRef))
If you are looking for open modules, "close(m)" has just got to be wrong.

I don't see where you are modifying the module; if so "save(m)" doesn't do anything; and you don't need the "edit" command.

"m" as global variable doesn't feel right, but I cannot tell exactly. It makes sense if one of your buttons needs to tell another button which open module it last dealt with; but I don't think you do that. If "m" represents the original module the code is run from, then do NOT use "m" in all your functions.

-Louie

Re: Can't see the error
Bruwbruw - Tue Aug 21 13:28:00 EDT 2012

llandale - Wed Aug 15 10:42:35 EDT 2012
This is impossible to follow, you need to post the entire code in one block.
What does "doesn't work" mean exactly?

I notice that Skip modNameList ..

  • has the base name as the "key"; which will fail if you have two modules with the same name open. Change the put() to one of these:
    • put(modNameList, fullName(itemRef), fullName(itemRef))
    • put(modNameList, itemRef, fullName(itemRef))
    • put(modNameList, count, fullName(itemRef))
  • has a 'string' key; so you MUST use "createString()" instead of just "create". (Unless you use "itemRef" or "count" as the key)

I think you want to use "for m in project do" to find Modules open in the Project. Looping for all items and using "canModify" doesn't feel right.
  • If so, this is an option:
    • put(modNameList, mod, fullName(itemRef))
If you are looking for open modules, "close(m)" has just got to be wrong.

I don't see where you are modifying the module; if so "save(m)" doesn't do anything; and you don't need the "edit" command.

"m" as global variable doesn't feel right, but I cannot tell exactly. It makes sense if one of your buttons needs to tell another button which open module it last dealt with; but I don't think you do that. If "m" represents the original module the code is run from, then do NOT use "m" in all your functions.

-Louie

Sorry, the main problem is that I did not have time to stop and analize the dxl.
The error that I cannot see is, I created the dxl with the objective of filling the attributes Q1CSYS and Q2CSYS in all open modules from a project.
The problem is that the dxl is only filling these attributes from the module that I run the dxl, and the other modules opened in exclusive edit, nothing happens.

If I get stuck in this problem, I'll have to think of another possibility. Anyway I appreciate the patience.
Obviously now I understand what my teacher always said: a code that you stay more than three months without seeing, is almost like a code created by another person.

There is the code:
 

/*===================================================================================
 Date: ??/08/2011
 Bruna Aquino
=========================================================================================*/
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                        //////////////  Variables //////////////
*=====*=====*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
Project pSys = project "/EMB550_04_Systems"
Object obj = current
Module m
string parentPrj, parentFolder, moduleName, fullModName
int count = 0
int iQC1, iQC2
string currentQC1, currentQC2
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                                  /////////////// Interface Items ////////////////
*=====*=====*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
DB verEvidenceBox = create("Synoptics Completeness Validation Checklist - Rev (-)")
 
DBE tagField, statusField, authorField
DBE selectChoiceQC1, selectChoiceQC2
DBE richTextReq, richTextApp, textMultiLine, selectHelp
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                             ///////////////    Answer Types ////////////////
*=====*=====*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
string options[] = {"YES", "NO", "Not Evaluated"}
string errMess = "Error creating type."
AttrType answerType = find(current Module, "Answer")
if (null answerType) answerType = create ("Answer", options, errMess)
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                                        ///////////////  Functions  //////////////
*=====*=====*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
void deleteAttrDef(string s){ 
  AttrDef ad = find(current Module, s) 
  if (null ad) // print "Attr Def  '" s "' does not exist.\n"
  else delete(ad) 
} 
/*=====*=====*=====*=====*======*=====*=====*======*======*======*======*=====*=====*====*/     
 
void deleteAttrType(string s){
  string err = "" 
  AttrType at = find(current Module, s)   
  if (null at) // print "Attr Type  '" s "' does not exist.\n"
  else delete(at, err)  
} 
 
/*=====*=====*=====*=====*======*=====*=====*======*======*======*======*=====*=====*====*/     
// Status field will always reflect the actual answers for all questions
void setStatus(){     
    m = current Module
        bool ValInd, NotEvalInd, NotValInd
        ValInd = false
        NotEvalInd = false
        NotValInd = false
                
        if (m."Validation Q1CSYS" ""=="YES" && m."Validation Q2CSYS" ""=="YES") {
                          ValInd = true
                          }   
        else {       
        if (m."Validation Q1CSYS" ""=="Not Evaluated" && m."Validation Q2CSYS" ""=="Not Evaluated") {
                NotEvalInd = true
         }else NotValInd = true 
}
        
        if (NotValInd) {
                m."Completeness Validation Status" = "Not Valid"
                } else if (NotEvalInd){
                m."Completeness Validation Status" =  "Not Validated"
                } else m."Completeness Validation Status" = "Valid" 
}
 
 
/*=====*=====*=====*=====*======*=====*=====*======*======*======*======*=====*=====*====*/             
// Return the last author of the current object
string lastObjectTextModifier(){
        History h 
        string lastAuthor = ""
    for h in current Object do {
            HistoryType ht = h.type 
                if (ht == modifyObject && h.attrName == "Object Text") lastAuthor = h.author 
        }
        return lastAuthor
}
 
void updateVariables() {
    m = current Module
        string currentQC1 = m."Validation Q1CSYS" ""
        string currentQC2 = m."Validation Q2CSYS" ""
                        
        for iQC1 in 0:3 by 1 do {
                if (currentQC1 == answerType.strings[iQC1]) { break }
                iQC1++
        }
        for iQC2 in 0:3 by 1 do {
                if (currentQC2 == answerType.strings[iQC2]) { break }
                iQC2++
        }
                        
        set(selectChoiceQC1,iQC1)
        set(selectChoiceQC2,iQC2)
        set(textMultiLine, m."Completeness Validation Comments" "")
        setStatus()             
        refresh current Module
}
            
 
 /*=====*======*=====*=====*=====*=====*=====*======*======*======*======*=====*=====*====*/    
bool notExistAttribute(string aName){        
        AttrDef ad = find(current Module, aName) 
        if (null ad) return true
        else return false
}
/*=====*======*=====*=====*=====*=====*=====*======*======*======*======*=====*=====*====*/     
 
// Save all validation questions and Validation Comments
void saveObjects(){
    User u = find() // returns current user login.
    string userLogin = u.name
        string aux = ""
        int i
        bool wasModified = false
        m = current Module
 
    if (get(selectChoiceQC1) =="NO" || get(selectChoiceQC2)=="NO" ) {
        return
        }
        
            if(canModify(m)){
                    
                        aux = get(selectChoiceQC1)
                        if(m."Validation Q1CSYS" "" != aux) {
                                m."Validation Q1CSYS" = aux
                                wasModified = true
                                }
                        aux = get(selectChoiceQC2)
                        if(m."Validation Q2CSYS" "" != aux) {
                                m."Validation Q2CSYS" = aux
                                wasModified = true
                                }            
                                
                    aux = get(textMultiLine)
                        if(m."Completeness Validation Comments" "" != aux) {
                                m."Completeness Validation Comments" = get(textMultiLine)
                                wasModified = true
                        }
                                                // Save checker
                        if(wasModified){     // Saves Checker just if something has changed.
                                User u = find() // returns current user login.          
                                string uName    = u.name
                                obj."Completeness Checker" = uName// just save if is requirement.
                                }
                            }
 
        else infoBox "Cannot modify current object."
}
 
        
 
/*=====*======*=====*=====*=====*=====*=====*======*======*======*======*=====*=====*====*/     
void saveReport(DB calledFrom){      
        saveObjects() // Saves all validation questions and Validation Comments.        
        save(current Module)
        refresh (current Module)        
 }
 
 
/*=====*=====*=====*=====*======*=====*=====*======*======*======*======*=====*=====*====*/     
void closeBox(DB calledFrom){        
        if(unsaved(current Module)){                 
                string buttons[] = {"Yes", "No"} 
                int answer = messageBox("To save the validation, save current module. \nSave current module?", buttons, msgWarning) 
                if(buttons[answer] == "Yes") {
                        saveObjects() // Saves all validation questions and Validation Comments.        
                        save(current Module)
                        refresh (current Module)        
                }    
        }
        hide calledFrom
}
 
/*=====*=====*=====*=====*=====*=====*=====*======*======*======*======*=====*=====*====*/      
bool notExistAttribute(string attrName){
        AttrDef ad = find(current Module, attrName) 
        if (null ad) return true
        else {
 
                return false
        }
}
 
/* 
 //Project pSys = project "/EMB550_04_Systems"
Module m
for m in current Project do{
if (isEdit m)
print m."Name" "\n"
}*/
 
for m in pSys do{            
if (isEdit m){
   setStatus()
   updateVariables()
   saveObjects()
        }
}
 
/*=====*======*=====*======*======*=====*=====*======*======*======*======*=====*=====*===
                        //////////////////  Main Program  //////////////////
*=====*======*=====*======*======*=====*=====*======*======*======*======*=====*=====*===*/
 
// Start to buid GUI
    saveButton = apply(verEvidenceBox, "&Save Module", saveReport)
        close(verEvidenceBox, true, closeBox)
 
        // Questions 
        selectChoiceQC1 = choice(verEvidenceBox, "Q1: ?", options, 1, 13,false)
        
        selectChoiceQC2 = choice(verEvidenceBox, "Q2: ?", options, 1, 13,false)
                
        statusField = field(verEvidenceBox, "Completeness Validation Status", "", 13, true)
        
        textMultiLine = text(verEvidenceBox, "Completeness Validation Comments","", 30, 60, false )
        
        realize verEvidenceBox
        updateVariables()       
        show verEvidenceBox

Re: Can't see the error
llandale - Tue Aug 21 15:35:39 EDT 2012

Bruwbruw - Tue Aug 21 13:28:00 EDT 2012

Sorry, the main problem is that I did not have time to stop and analize the dxl.
The error that I cannot see is, I created the dxl with the objective of filling the attributes Q1CSYS and Q2CSYS in all open modules from a project.
The problem is that the dxl is only filling these attributes from the module that I run the dxl, and the other modules opened in exclusive edit, nothing happens.

If I get stuck in this problem, I'll have to think of another possibility. Anyway I appreciate the patience.
Obviously now I understand what my teacher always said: a code that you stay more than three months without seeing, is almost like a code created by another person.

There is the code:
 

/*===================================================================================
 Date: ??/08/2011
 Bruna Aquino
=========================================================================================*/
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                        //////////////  Variables //////////////
*=====*=====*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
Project pSys = project "/EMB550_04_Systems"
Object obj = current
Module m
string parentPrj, parentFolder, moduleName, fullModName
int count = 0
int iQC1, iQC2
string currentQC1, currentQC2
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                                  /////////////// Interface Items ////////////////
*=====*=====*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
DB verEvidenceBox = create("Synoptics Completeness Validation Checklist - Rev (-)")
 
DBE tagField, statusField, authorField
DBE selectChoiceQC1, selectChoiceQC2
DBE richTextReq, richTextApp, textMultiLine, selectHelp
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                             ///////////////    Answer Types ////////////////
*=====*=====*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
string options[] = {"YES", "NO", "Not Evaluated"}
string errMess = "Error creating type."
AttrType answerType = find(current Module, "Answer")
if (null answerType) answerType = create ("Answer", options, errMess)
 
/*=====*======*======*======*======*=====*=====*======*======*======*======*=====*=====*===
                                        ///////////////  Functions  //////////////
*=====*=====*======*======*======*=====*=====*======*======*======*======*=====*=====*===*/
void deleteAttrDef(string s){ 
  AttrDef ad = find(current Module, s) 
  if (null ad) // print "Attr Def  '" s "' does not exist.\n"
  else delete(ad) 
} 
/*=====*=====*=====*=====*======*=====*=====*======*======*======*======*=====*=====*====*/     
 
void deleteAttrType(string s){
  string err = "" 
  AttrType at = find(current Module, s)   
  if (null at) // print "Attr Type  '" s "' does not exist.\n"
  else delete(at, err)  
} 
 
/*=====*=====*=====*=====*======*=====*=====*======*======*======*======*=====*=====*====*/     
// Status field will always reflect the actual answers for all questions
void setStatus(){     
    m = current Module
        bool ValInd, NotEvalInd, NotValInd
        ValInd = false
        NotEvalInd = false
        NotValInd = false
                
        if (m."Validation Q1CSYS" ""=="YES" && m."Validation Q2CSYS" ""=="YES") {
                          ValInd = true
                          }   
        else {       
        if (m."Validation Q1CSYS" ""=="Not Evaluated" && m."Validation Q2CSYS" ""=="Not Evaluated") {
                NotEvalInd = true
         }else NotValInd = true 
}
        
        if (NotValInd) {
                m."Completeness Validation Status" = "Not Valid"
                } else if (NotEvalInd){
                m."Completeness Validation Status" =  "Not Validated"
                } else m."Completeness Validation Status" = "Valid" 
}
 
 
/*=====*=====*=====*=====*======*=====*=====*======*======*======*======*=====*=====*====*/             
// Return the last author of the current object
string lastObjectTextModifier(){
        History h 
        string lastAuthor = ""
    for h in current Object do {
            HistoryType ht = h.type 
                if (ht == modifyObject && h.attrName == "Object Text") lastAuthor = h.author 
        }
        return lastAuthor
}
 
void updateVariables() {
    m = current Module
        string currentQC1 = m."Validation Q1CSYS" ""
        string currentQC2 = m."Validation Q2CSYS" ""
                        
        for iQC1 in 0:3 by 1 do {
                if (currentQC1 == answerType.strings[iQC1]) { break }
                iQC1++
        }
        for iQC2 in 0:3 by 1 do {
                if (currentQC2 == answerType.strings[iQC2]) { break }
                iQC2++
        }
                        
        set(selectChoiceQC1,iQC1)
        set(selectChoiceQC2,iQC2)
        set(textMultiLine, m."Completeness Validation Comments" "")
        setStatus()             
        refresh current Module
}
            
 
 /*=====*======*=====*=====*=====*=====*=====*======*======*======*======*=====*=====*====*/    
bool notExistAttribute(string aName){        
        AttrDef ad = find(current Module, aName) 
        if (null ad) return true
        else return false
}
/*=====*======*=====*=====*=====*=====*=====*======*======*======*======*=====*=====*====*/     
 
// Save all validation questions and Validation Comments
void saveObjects(){
    User u = find() // returns current user login.
    string userLogin = u.name
        string aux = ""
        int i
        bool wasModified = false
        m = current Module
 
    if (get(selectChoiceQC1) =="NO" || get(selectChoiceQC2)=="NO" ) {
        return
        }
        
            if(canModify(m)){
                    
                        aux = get(selectChoiceQC1)
                        if(m."Validation Q1CSYS" "" != aux) {
                                m."Validation Q1CSYS" = aux
                                wasModified = true
                                }
                        aux = get(selectChoiceQC2)
                        if(m."Validation Q2CSYS" "" != aux) {
                                m."Validation Q2CSYS" = aux
                                wasModified = true
                                }            
                                
                    aux = get(textMultiLine)
                        if(m."Completeness Validation Comments" "" != aux) {
                                m."Completeness Validation Comments" = get(textMultiLine)
                                wasModified = true
                        }
                                                // Save checker
                        if(wasModified){     // Saves Checker just if something has changed.
                                User u = find() // returns current user login.          
                                string uName    = u.name
                                obj."Completeness Checker" = uName// just save if is requirement.
                                }
                            }
 
        else infoBox "Cannot modify current object."
}
 
        
 
/*=====*======*=====*=====*=====*=====*=====*======*======*======*======*=====*=====*====*/     
void saveReport(DB calledFrom){      
        saveObjects() // Saves all validation questions and Validation Comments.        
        save(current Module)
        refresh (current Module)        
 }
 
 
/*=====*=====*=====*=====*======*=====*=====*======*======*======*======*=====*=====*====*/     
void closeBox(DB calledFrom){        
        if(unsaved(current Module)){                 
                string buttons[] = {"Yes", "No"} 
                int answer = messageBox("To save the validation, save current module. \nSave current module?", buttons, msgWarning) 
                if(buttons[answer] == "Yes") {
                        saveObjects() // Saves all validation questions and Validation Comments.        
                        save(current Module)
                        refresh (current Module)        
                }    
        }
        hide calledFrom
}
 
/*=====*=====*=====*=====*=====*=====*=====*======*======*======*======*=====*=====*====*/      
bool notExistAttribute(string attrName){
        AttrDef ad = find(current Module, attrName) 
        if (null ad) return true
        else {
 
                return false
        }
}
 
/* 
 //Project pSys = project "/EMB550_04_Systems"
Module m
for m in current Project do{
if (isEdit m)
print m."Name" "\n"
}*/
 
for m in pSys do{            
if (isEdit m){
   setStatus()
   updateVariables()
   saveObjects()
        }
}
 
/*=====*======*=====*======*======*=====*=====*======*======*======*======*=====*=====*===
                        //////////////////  Main Program  //////////////////
*=====*======*=====*======*======*=====*=====*======*======*======*======*=====*=====*===*/
 
// Start to buid GUI
    saveButton = apply(verEvidenceBox, "&Save Module", saveReport)
        close(verEvidenceBox, true, closeBox)
 
        // Questions 
        selectChoiceQC1 = choice(verEvidenceBox, "Q1: ?", options, 1, 13,false)
        
        selectChoiceQC2 = choice(verEvidenceBox, "Q2: ?", options, 1, 13,false)
                
        statusField = field(verEvidenceBox, "Completeness Validation Status", "", 13, true)
        
        textMultiLine = text(verEvidenceBox, "Completeness Validation Comments","", 30, 60, false )
        
        realize verEvidenceBox
        updateVariables()       
        show verEvidenceBox

"m = current" throughout is a disaster in general and the culprit in this case.

I would add "Module m" as a parameter to functions "saveObjects()" and also "updateVariables()", and in fact to every other function that deals with a "Module".

Change the first two lines of updateVariables() to this, to see what you are doing:
  • void updateVariables() {
  • print ">>updateVariables m = " (name(m)) "\n"
  • m = current Module
  • print ">>updateVariables m = " (name(m)) "\n"
You loop through all modules, but update only the original one.

In generaly, avoid global variables as best you can. Common exceptions will be DB and DBE and your main data structures (shared by lots of functions); and stuff that doesn't change like "Module mCurr = current".

-Louie